﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// Summary description for CUser
/// </summary>
public class CUser
{
    private string _UserName, _PassWord;
    //them cac thong tin can thiet cho cap nhat
    CMyCart _cart;
    public CUser()
    {
        _UserName = "ko biet ok";
        _PassWord = "ko biet ok";
        _cart = new CMyCart();

    }
    public void InitCart()
    {
        _cart = new CMyCart();
    }
    public CMyCart Cart
    {
        get { return _cart; }
        set { _cart = value; }
    }

    public string PassWord
    {
        get { return _PassWord; }
        set { _PassWord = value; }
    }

    public string UserName
    {
        get { return _UserName; }
        set { _UserName = value; }
    }

    public CUser(string username,string password)
    {
        _UserName= username;
        _PassWord = password;
    }
    public bool IsValidLogin()    
    {
        DataTable dt = CustomerAccess.GetCustomer(_UserName, _PassWord);
        if (dt.Rows.Count > 0)
        {
            // gán các thông tin khác của user vào cac thuôc tính của lớp tại đay
            return true;
        }
        return false;
    }
    public static string MD5(string password)
    {
        byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
        try
        {
            System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
            cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] hash = cryptHandler.ComputeHash(textBytes);
            string ret = "";
            foreach (byte a in hash)
            {
                if (a < 16)
                    ret += "0" + a.ToString("x");
                else
                    ret += a.ToString("x");
            }
            return ret;
        }
        catch
        {
            throw;
        }
    }
	
}
